package BadBoy;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.SplashScreen;
import java.awt.geom.Rectangle2D;

import javax.swing.ImageIcon;

public class splash {
    static Graphics2D   splashGraphics;
    static Rectangle2D.Double splashTextArea;
    static Rectangle2D.Double splashProgressArea;
    static Font font;
    static  SplashScreen mySplash;
    /**
     * just a stub to simulate a long initialization task that updates
     * the text and progress parts of the status in the Splash
     */
	public static void appInit()
	{
		for(int i=1;i<=10;i++)
		{
			int pctDone = i*10;
			splashText("Doing task #" + i);
			 splashProgress(pctDone);            // give them an idea how much we have completed
	            try
	            {
	                Thread.sleep(1000);             // wait a second
	            }
	            catch (InterruptedException ex)
	            {
	                break;
	            }
		}
	}
	public static void splashInit()
    {
        // the splash screen object is created by the JVM, if it is displaying a splash image
	    mySplash = SplashScreen.getSplashScreen();
        // if there are any problems displaying the splash image
        // the call to getSplashScreen will returned null

        if (mySplash != null)
        {
            // get the size of the image now being displayed
            Dimension ssDim = mySplash.getSize();
            int height = ssDim.height;
            int width = ssDim.width;

            // stake out some area for our status information
            splashTextArea = new Rectangle2D.Double(15., height*0.88, width * .45, 32.);
            splashProgressArea = new Rectangle2D.Double(width * .55, height*.92, width*.4, 12 );

            // create the Graphics environment for drawing status info
            splashGraphics = mySplash.createGraphics();
            font = new Font("Dialog", Font.PLAIN, 14);
            splashGraphics.setFont(font);

            // initialize the status info
            splashText("Starting");
            splashProgress(0);
        }
    }
	public static void splashText(String str)
	{
		if(mySplash != null && mySplash.isVisible())
		{
			//important to check here so no other method need to know if there
			//really is a splash being displayed
			//erase the last status text
			splashGraphics.setPaint(Color.LIGHT_GRAY);
			splashGraphics.fill(splashTextArea);
			//draw  the text
			splashGraphics.setPaint(Color.BLACK);
			splashGraphics.drawString(str, (int)(splashTextArea.getX() + 10),(int)(splashTextArea.getY() + 15));
			//make sure it 's display
			mySplash.update();
		}
		
	}
	public static void splashProgress(int pct)
	{
		if((mySplash != null)&&(mySplash.isVisible()))
		{
			// Note: 3 colors are used here to demonstrate steps
            // erase the old one
			splashGraphics.setPaint(Color.BLUE);
			splashGraphics.fill(splashProgressArea);
			// draw an outline
            splashGraphics.setPaint(Color.BLUE);
            splashGraphics.draw(splashProgressArea);

            // Calculate the width corresponding to the correct percentage
            int x = (int) splashProgressArea.getMinX();
            int y = (int) splashProgressArea.getMinY();
            int wid = (int) splashProgressArea.getWidth();
            int hgt = (int) splashProgressArea.getHeight();

            int doneWidth = Math.round(pct*wid/100.f);
            doneWidth = Math.max(0, Math.min(doneWidth, wid-1));  // limit 0-width

            // fill the done part one pixel smaller than the outline
            splashGraphics.setPaint(Color.GREEN);
            splashGraphics.fillRect(x, y+1, doneWidth, hgt-1);

            // make sure it's displayed
            mySplash.update();
		}
	}
}
